package com.haochang.chunkvod.controller.activity.login;

import com.haochang.base.BaseActivity;
import com.haochang.base.BaseActivityManager;
import com.haochang.base.BaseEditText;
import com.haochang.base.BaseTextView;
import com.haochang.base.OnBaseClickListener;
import com.haochang.chunkvod.R;
import com.haochang.chunkvod.app.common.user.UserToken;
import com.haochang.chunkvod.app.utils.ToastUtils;
import com.haochang.chunkvod.view.vod.title.TitleView;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;

/**
 *@author qintao
 *created at 2016/6/3 16:16
 * 密码修改
 */

public class PasswordModifyActivity extends BaseActivity
{

	private TitleView titleView;
	private BaseTextView tv_account;
	private BaseEditText et_old_pwd;
	private BaseEditText et_new_pwd;
	private BaseEditText et_sure_pwd;
	private Button btn_modify;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
	}

	@Override
	public void receiveParam()
	{

	}

	@Override
	public void initData()
	{

	}

	@Override
	public void initViews()
	{
		setContentView(R.layout.activity_password_modify);
		titleView = (TitleView) findViewById(R.id.titleView);
		titleView.setTitle(R.string.password_modify).setRightIconVISIBLE(false).setTitleOnClickListener(new TitleView.ITitleOnClickListener()
		{
			@Override
			public void onBackClick()
			{
				finish();
			}

			@Override
			public void onDoneClick()
			{

			}
		});
		tv_account = (BaseTextView) findViewById(R.id.tv_account);
		et_old_pwd = (BaseEditText) findViewById(R.id.et_old_pwd);
		et_new_pwd = (BaseEditText) findViewById(R.id.et_new_pwd);
		et_sure_pwd = (BaseEditText) findViewById(R.id.et_sure_pwd);
		btn_modify = (Button) findViewById(R.id.btn_modify);
		btn_modify.setOnClickListener(mOnBaseClickListener);
	}

	private OnBaseClickListener mOnBaseClickListener = new OnBaseClickListener()
	{
		@Override
		public void onBaseClick(View v)
		{
			switch (v.getId())
			{
			case R.id.btn_modify:
				String old_pwd = et_old_pwd.getText().toString();
				String new_pwd = et_new_pwd.getText().toString();
				String user_pwd = et_sure_pwd.getText().toString();
				if (TextUtils.isEmpty(old_pwd))
				{
					ToastUtils.makeText(PasswordModifyActivity.this, "当前密码不可为空", ToastUtils.TOAST_TIME).show();
					return;
				}
				if (TextUtils.isEmpty(new_pwd) || TextUtils.isEmpty(user_pwd))
				{
					ToastUtils.makeText(PasswordModifyActivity.this, "新密码不可为空", ToastUtils.TOAST_TIME).show();
					return;
				}
				if (!new_pwd.equals(user_pwd))
				{
					ToastUtils.makeText(PasswordModifyActivity.this, "两次输入的新密码不一致", ToastUtils.TOAST_TIME).show();
					return;
				}
				if (new_pwd.length() < 6)
				{
					ToastUtils.makeText(PasswordModifyActivity.this, "新密码不可少于6个字符", ToastUtils.TOAST_TIME).show();
					return;
				}
				if (new_pwd.length() > 16)
				{
					ToastUtils.makeText(PasswordModifyActivity.this, "新密码不可多于16个字符", ToastUtils.TOAST_TIME).show();
					return;
				}
				if (old_pwd.equals(new_pwd))
				{
					ToastUtils.makeText(PasswordModifyActivity.this, "新密码不可与当前密码相同", ToastUtils.TOAST_TIME).show();
					return;
				}
				// TODO: 2016/6/3 做密码修改操作
				ToastUtils.makeText(PasswordModifyActivity.this, "修改密码成功", ToastUtils.TOAST_TIME).show();
				Intent intent = new Intent(PasswordModifyActivity.this, LoginActivity.class)
						.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
				//修改密码成功跳转到登录界面，关闭之前的所有activity
				//				BaseActivityManager.getInstance().closeAllActivity();
				startActivity(intent);
				UserToken.reset();
				break;

			default:
				break;
			}
		}
	};
}
